// 加密
function encrypt (word) {
  let keyStr = 'hoxdVJUbrulsdcqMFy2rWlSmlasn8kea'
  let ivStr = 'VWz35S5kltEAJ1Q1'
  let key = CryptoJS.enc.Utf8.parse(keyStr)
  let iv = CryptoJS.enc.Utf8.parse(ivStr)
  let srcs = CryptoJS.enc.Utf8.parse(word)

  let encrypted = CryptoJS.AES.encrypt(srcs, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7 //实测如果使用ZeroPadding后端会报bad padding错误
  })
  return encrypted.ciphertext.toString()
}


function decrypt (ciphertext) {
  let keyStr = 'hoxdVJUbrulsdcqMFy2rWlSmlasn8kea';
  let ivStr = 'VWz35S5kltEAJ1Q1';
  let key = CryptoJS.enc.Utf8.parse(keyStr);
  let iv = CryptoJS.enc.Utf8.parse(ivStr);

  let encryptedHexStr = CryptoJS.enc.Hex.parse(ciphertext);
  let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);

  let decrypt = CryptoJS.AES.decrypt(srcs, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });

  let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr;
}